<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jQuery/jquery-2.1.4.min.js"  type='text/javascript'></script>
</head>
<body>
<div id="myDiv"><h2>点击进行跳转测试</h2></div>
<button id="b01" type="button">Change Content</button>
<div id="testEl"></div>

<script type="text/javascript">


    var getRequestParams=function () {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = {};
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    };


    $(document).ready(function(){
        $("#b01").click(function(){
            var data=$.ajax({url:"/cms/manage/wechat/component/createPreAuthCode",async:false});
            data=data.responseJSON.data;
            var baseHref="https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid="+data.appId;

            baseHref+="&pre_auth_code="+encodeURIComponent(data.preAuthCode.pre_auth_code);
            baseHref+="&redirect_uri="+encodeURIComponent("http://kebohui.viphk.ngrok.org/webAppTest/wechatRedirect.html");
            window.location.href=baseHref;
        });


        var params=getRequestParams();
        if(params["auth_code"]!=null || params["auth_code"]!=undefined)
        {
            var data=$.ajax({url:"/cms/manage/wechat/component/queryAuth",
                "type":"POST",
                "data":{"auth_code":params["auth_code"]},
                async:false});

            $("#testEl").html(data.responseText);
        }
    });
</script>
</body>
</html>